package net.kehuilai;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;


@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    private SocketClient socketClient;

    @Bean
    public SocketClient socketClient() {
        return this.socketClient;
    }

    /* 启动Server */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    @PostConstruct
    public void init() {
        this.socketClient = new SocketClient("127.0.0.1", 20550);
        this.socketClient.start();
    }

    @PreDestroy
    public void destroy() {
        this.socketClient.close();
    }
}
